package com.controller.manage;

  
import java.io.IOException;
  
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.web.filter.OncePerRequestFilter;

import com.po.Adminmain;
import com.service.manage.imp.SessionListener;
/**
 * 登录过滤器
 * @author wangli
 *
 */

public class SessionFilter extends OncePerRequestFilter {
  
   
    @Override
    protected void doFilterInternal(HttpServletRequest request,
            HttpServletResponse response, FilterChain filterChain)
            throws ServletException, IOException {
    	HttpServletRequest req=(HttpServletRequest)request;
		String str = req.getRequestURI();
		HttpSession session=req.getSession();
		Adminmain admin=(Adminmain)session.getAttribute("admin");
		boolean login =false;
		
		if(SessionListener.user_session!=null && admin!=null){
			login = SessionListener.user_session.get(admin.getAdminid()).getId().equals(session.getId());
		}
		//正常转发登录，或者是已经登录
		if((str.indexOf("login")!=-1)||login){
			filterChain.doFilter(request, response);
		}
		else
		{
			request.getRequestDispatcher("redirect.jsp").forward(request,response);
		}
       
        }
    }
  
